<?php
/**
 * sitedefine.php
 * Create on 2015-03-25 10:48:38
 * Create by yuebin
 */
namespace haibao\cms\business\site;
use haibao\cms\business\BusinessException;
use haibao\cms\data\site\SiteChannel as SiteChannelData;

class SiteChannel extends \haibao\cms\business\Base{

	const BLOG_CATE_LIST = 'BLOG_CATE_LIST';
	const DAILY_BITCH_LIST = 'DAILY_BITCH_LIST';
	const TALK_SHOW_LIST = 'TALK_SHOW_LIST';
	const DAILY_BITCH_INDEX = 'DAILY_BITCH_INDEX';
	const TALK_SHOW_INDEX = 'TALK_SHOW_INDEX';
	const FEATURE_LIST = 'FEATURE_LIST';
	const FEATURE_FLOW_LIST = 'FEATURE_FLOW_LIST';
	const VIDEO_SQUARE_LIST = 'VIDEO_SQUARE_LIST';
	const VIDEO_FLOW_LIST = 'VIDEO_FLOW_LIST';
	
	const SPECIAL_TAG_LIST = 'SPECIAL_TAG_LIST';//特殊标签列表
	
	/**
	 * 添加站点频道
	 * @param : Object \haibao\cms\model\data\site\SiteChannel $siteChannelModel
	 */
	public static function addSiteChannel($siteChannelModel){
	
		self::checkOperation(self::FUNC_CODE_SITE_CHANNEL_ADD);
	
		if(!$siteChannelModel->ChannelName){
			throw new BusinessException('站点频道名不能为空');
		}
		if(!$siteChannelModel->ChannelUrl){
			throw new BusinessException('站点频道URL不能为空');
		}
		$siteChannelData = new SiteChannelData();
		$siteChannelData->addSiteChannel($siteChannelModel);
	
		self::saveOperateHistory(self::FUNC_CODE_SITE_CHANNEL_ADD, $siteChannelModel->toArray(true,true));
	
	}
	
	/**
	 * 更新站点频道
	 * @param : Object \haibao\cms\model\data\site\SiteChannel $siteChannelModel
	 */
	public static function updateSiteChanneleById($siteChannelModel){
	
		self::checkOperation(self::FUNC_CODE_SITE_CHANNEL_EDIT);
	
		if(!$siteChannelModel->ChannelName){
			throw new BusinessException('站点频道名不能为空');
		}
		if(!$siteChannelModel->ChannelUrl){
			throw new BusinessException('站点频道URL不能为空');
		}
		$siteChannelData = new SiteChannelData();
		$siteChannelData->updateSiteChanneleById($siteChannelModel);
	
		self::saveOperateHistory(self::FUNC_CODE_SITE_CHANNEL_EDIT, $siteChannelModel->toArray(true,true));
	
	}	
	
	/**
	 * 根据频道ID删除频道信息
	 * @param : Int $channelId
	 */
	public static function deleteSiteChannelById($channelId,$status = \haibao\cms\model\data\site\SiteChannel::STATUS_DIS_ENABLE){
	
		self::checkOperation(self::FUNC_CODE_SITE_CHANNEL_DELETE);
		if(!$channelId){
			throw new BusinessException('站点频道ID不能为空');
		}
	
		$siteChannelData = new SiteChannelData();
		$siteChannelData->deleteSiteChannelById($channelId,$status);
		self::saveOperateHistory(self::FUNC_CODE_SITE_CHANNEL_DELETE, array($channelId,$status));
	}
	
	/**
	 * 获取站点频道信息
	 * @param : Int $channelId
	 */
	public static function getSiteChannelById($channelId){
		
		$data = new SiteChannelData();
		return $data->getSiteChannelById($channelId);
	}	
	/**
	 * 获取站点频道信息
	 * @param : Object $filter
	 * @param : Int $isOne 是否取一条
	 */
	public static function getSiteChannelByFilter($filter,$isOne = true){
		
		$data = new SiteChannelData();
		if($isOne){
			$siteChannels = $data->getOne($filter);
		}else{

			$siteChannels = $data->getAll($filter);
		}
		return $siteChannels;
	}

	
	/**
	 * 判断当前频道是否存在子频道 （未删除）
	 * @pamam : Int $channelId
	 */
	public static function isExistChildChannel($channelId){
	
		$siteChannelData = new SiteChannelData();
		return $siteChannelData->isExistChildChannel($channelId);
	}
	/**
	 * 判断当前频道是否存在父频道（未删除）
	 * @pamam : Int $parentId
	 */
	public static function isExistParentChannel($parentId){
	
		$siteChannelData = new SiteChannelData();
		return $siteChannelData->isExistParentChannel($parentId);
	}
	
	/**
	 * 根据站点频道名字获取站点信息
	 * @param : String $channelName
	 * @param : Int $channelId
	 */
	public static function getSiteChannelByChannelName($channelName, $channelId = null){
		$data = new SiteChannelData;
		return $data->getSiteChannelByChannelName($channelName,$channelId);
	}


	/**
	 * 配置站点频道编码
	 */
	public static function getSiteChannelCode($codeName = null){
	
		$channelCode = array(
				'BLOG_CATE_LIST'=>'自媒体分类列表',
				'DAILY_BITCH_LIST'=>'每日一贱列表',
				'DAILY_BITCH_INDEX'=>'每日一贱首页',
				'TALK_SHOW_INDEX'=>'脱口秀首页',
				'TALK_SHOW_LIST'=>'脱口秀列表',
				'FEATURE_LIST'=>'专题列表',
				'FEATURE_FLOW_LIST'=>'专题流布局列表',
				'VIDEO_SQUARE_LIST'=>'视频方格布局列表',
				'VIDEO_FLOW_LIST'=>'视频流布局列表',
				'CALENDAR_LIST'=>'造型日历标签列表',
				'TV_TAG_LIST'=>'美剧标签列表',
				'JIEMENG_SEARCH_LIST'=>'解梦搜索页',
		        'JIEMENG_TAG_LIST'=>'解梦标签列表',
		        'SPECIAL_TAG_LIST'=>'特殊标签列表',
		        'ARTICLE_DETAIL' =>'文章详情页右侧',
					
		);
		if($codeName){
			return $channelCode[$codeName];
		}
		return $channelCode;
	}
	
}
